<?php
error_reporting(0);
ini_set('memory_limit', '1000M');
set_time_limit(0);


/** 
 *  mapper_6.php
 *      input:格式：mapred3输出 (json1\tjson2\t...)尤其要注意其中的weight字段
 *      handle:生成sql
 *      output:sql语句--INSERT INTO `house_rent_bad` VALUES ('1', ...);
 * @created 2016-03-09
 * @by delia
 */
$nu=0;
while (($line_json = fgets(STDIN)) !== false) {   //line_json=>source_url\tjson格式
    if($nu==0){
	echo "INSERT INTO house_rent_bad(id,house_price,house_desc,house_title,cityarea_id,cityarea2_id,house_floor,house_topfloor,house_toward,house_room,house_hall,house_toilet,house_kitchen,house_fitment,owner_name,owner_phone,service_phone,created,updated,source,company_id,source_owner,app_url,wap_url,source_url,house_type,house_totalarea,borough_id,borough_name,house_pic_unit,house_pic_layout,house_number,is_fill,is_contrast,source_name,house_relet,sex,into_house,pay_type,pay_method,comment,deposit,house_configroom,house_configpub,is_ture,chain_url,bad_type,repeat_cnt,tag) VALUES";
        $nu=1;
    }        
    else{
	echo ",\n";
        $nu+=1;
    }
    $line_json = trim($line_json);
    if (empty($line_json))
        continue;
    $one_dejson=json_decode($line_json,true); 
    echo " ('".$one_dejson['id']."','".
	$one_dejson['house_price']."','".
	str_replace("'","",str_replace("\\","",$one_dejson['house_desc']))."','".
	str_replace("'","",str_replace("\\","",$one_dejson['house_title']))."','".
	$one_dejson['cityarea_id']."','".$one_dejson['cityarea2_id']."','".
	$one_dejson['house_floor']."','".$one_dejson['house_topfloor']."','".
	$one_dejson['house_toward']."','".$one_dejson['house_room']."','".
	$one_dejson['house_hall']."','".$one_dejson['house_toilet']."','".
	$one_dejson['house_kitchen']."','".$one_dejson['house_fitment']."','".
	str_replace("'","",$one_dejson['owner_name'])."','".
	$one_dejson['owner_phone']."','".
	$one_dejson['service_phone']."','".
	$one_dejson['created']."','".$one_dejson['updated']."','".
	$one_dejson['source']."','".$one_dejson['company_id']."','".
	$one_dejson['source_owner']."','".$one_dejson['app_url']."','".
	$one_dejson['wap_url']."','".$one_dejson['source_url']."','".
	$one_dejson['house_type']."','".
	$one_dejson['house_totalarea']."','".$one_dejson['borough_id']."','".
	str_replace("'","",str_replace("\\","",$one_dejson['borough_name']))."','".$one_dejson['house_pic_unit']."','".
	$one_dejson['house_pic_layout']."','".$one_dejson['house_number']."','".
	$one_dejson['is_fill']."','".$is_contrast."','".
	$one_dejson['source_name']."','".
	$one_dejson['house_relet']."','".$one_dejson['sex']."','".
        str_replace("'","",str_replace("\\","",$one_dejson['into_house']))."','".
	str_replace("'","",str_replace("\\","",$one_dejson['pay_type']))."','".
        str_replace("'","",str_replace("\\","",$one_dejson['pay_method']))."','".
	str_replace("'","",str_replace("\\","",$one_dejson['comment']))."','".
        str_replace("'","",str_replace("\\","",$one_dejson['deposit']))."','".
	str_replace("'","",str_replace("\\","",$one_dejson['house_configroom']))."','".
        str_replace("'","",str_replace("\\","",$one_dejson['house_configpub']))."','".
        $one_dejson['is_ture']."','".$one_dejson['chain_url']."','".
	$one_dejson['bad_type']."','".$one_dejson['repeat_cnt']."','".
	$one_dejson['tag']."')";	
    fwrite(STDERR, "reporter:counter:group_counter,bad_type ".$one_dejson['bad_type'].",1\n");
    fwrite(STDERR, "reporter:counter:group_counter,source ".$one_dejson['source'].",1\n");
	if($nu==19){
            echo ";\n";
            $nu=0;
        }

}
if($nu!=0)
{
    echo ";\n";	
}
?>

